package com.linkhub.oms.dao.mpservice;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.extension.mapping.base.MPJDeepService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.linkhub.oms.common.enums.mp.*;
import com.linkhub.oms.entity.OrderEntity;
import com.linkhub.oms.entity.resulttype.order.OrderInfoDO;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 订单表 服务类
 * </p>
 *
 * @author echo
 * @since 2024-03-28
 */
public interface IOrderService extends MPJDeepService<OrderEntity> {

    /**
     * 查询已同步的商店订单
     *
     * @param sysShopId    sysShopId
     * @param orderNumbers orderNumbers
     * @param columns      columns
     * @return orders
     */
    List<OrderEntity> listSynchronizedShopOrders(String sysShopId, Collection<String> orderNumbers, SFunction<OrderEntity, ?>... columns);

    List<OrderEntity> listShopOrders(String sysShopId, CustomerBusinessStatusEnum customerBusinessStatus);

    List<OrderEntity> listBySysOrderIds(List<String> sysOrderIds);

    List<OrderInfoDO> queryOrderWithLocalProducts(List<String> sysOrderIds);

    List<OrderInfoDO> queryOrderWithShopProducts(List<String> sysOrderIds);

    List<OrderEntity> deepMappingOrders(List<OrderEntity> orders);

    void updateCustomerBizState( List<String> sysShopIds,
                                 List<String> sysOrderIds,
                                 CustomerBusinessStatusEnum beforeState,
                                 CustomerBusinessStatusEnum afterState);


    void updateEmployeeBizState(List<String> sysOrderIds,
                                EmployeeBusinessStatusEnum beforeState,
                                EmployeeBusinessStatusEnum afterState);


    void updateOrderInfo(String sysOrderId, OrderEntity update);

    void updateOrderInfos(List<String> sysOrderIds, OrderEntity update);

    void submitFulfillments(Collection<String> sysOrderIds, List<String> inStockOrderIds);

    List<OrderEntity> listSubOrders(Collection<String> orderIds);

    OrderEntity getByOrderId(String sysOrderId, SFunction<OrderEntity, ?>... columns);

    OrderEntity getByOrderId(String sysOrderId);

    OrderEntity deepMappingByOrderId(String sysOrderId);

    boolean checkOrderExist(String sysShopId, String sysOrderId);

    void deleteByOrderIds(List<String> sysOrderIds);

    void logicDeleteByOrderIds(Collection<String> sysOrderIds);

    List<OrderEntity> listShopOrders(Collection<String> sysShopIds,
                                     Collection<String> sysOrderIds,
                                     SFunction<OrderEntity, ?>... columns);

    List<OrderEntity> listPendingProcessedSubOrders(Collection<String> sourceSysOrderIds);

    List<OrderEntity> listByJoinWrapper(MPJLambdaWrapper<OrderEntity> wrapper);


    boolean isLastFulfillmentSubOrder( OrderEntity orderEntity );

    /**
     * 根据用户id查询缺货订单id,根据提交履约时间排序
     * @param userId
     * @return
     */
    List<String> queryOutStockOrderIdsByUserId(String userId);

    boolean updateOrderStatus(String sysOrderId,
                              CustomerOrderStatusEnum before,
                              CustomerOrderStatusEnum update,
                              EmployeeOrderStatusEnum employeeBefore,
                              EmployeeOrderStatusEnum employeeUpdate,
                              OrderStockStatusEnum orderStockStatusEnumBefore,
                              OrderStockStatusEnum orderStockStatusEnumUpdate);

    List<OrderEntity> getByOrderStatus( OrderStatusEnum orderStatusEnum );

    List<OrderEntity> getNeedUpdateTrackingNUmber();

    OrderEntity getByWayBillNumber( String wayBillNumber );

    void batchUpdateTrackingNumById( List<OrderEntity> entityList );

    OrderEntity getByOrderNumber( String sysShopId, String orderNumber );
}
